package com.example.myapplication;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import java.util.Map;

public class adapter extends RecyclerView.Adapter<adapter.MyViewHolder>{
    private  List<Map<String, Object>> list;
    private Context context;
    private View inflater;

    public adapter(Context context, List<Map<String, Object>> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public adapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflater=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_item,viewGroup,false);
        MyViewHolder myHolder=new MyViewHolder(inflater);
        return myHolder;

    }

    @Override
    public void onBindViewHolder(adapter.MyViewHolder myHolder, int j) {

        Map<String,Object> currentItem =list.get(j);
        myHolder.imageView1.setImageResource((Integer) currentItem.get("name"));


        String str1=list.get(j).get("price").toString();
        String str2=list.get(j).get("config").toString();


        // myHolder.textView1.setText(list.get(j).get("name").toString());
        myHolder.textView2.setText(str1);
        myHolder.textView3.setText(str2);

        //launcher=registerForActivityResult(
        myHolder.imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, Activity_contact_detail.class);
                context.startActivity(intent);
                intent.putExtra("price",str1);
                intent.putExtra("config",str2);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        public ImageView imageView1;
        TextView textView1,textView2,textView3;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

            imageView1=itemView.findViewById(R.id.imageView_adapter);
            textView1=itemView.findViewById(R.id.rv_textView1);
            textView2=itemView.findViewById(R.id.rv_textView2);
            textView3=itemView.findViewById(R.id.rv_textView3);
        }
    }
}
